home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / CREAT.C < prev    next >
C/C++ Source or Header  |  1991-11-21  |  2KB  |  64 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    C R E A T . C                                                   */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <fcntl.h>
  13. #include <io.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*                    UUPC/extended include files                     */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. #include "lib.h"
  24. #include "hlib.h"
  25.  
  26. /*--------------------------------------------------------------------*/
  27. /*    C R E A T                                                       */
  28. /*                                                                    */
  29. /*    Create a file with the specified mode                           */
  30. /*--------------------------------------------------------------------*/
  31.  
  32. int CREAT(const char *name, const int mode, const char ftyp)
  33. {
  34.  
  35.    char *last;
  36.    char *path;
  37.    int results;
  38.  
  39.    /* are we opening for write or append */
  40.    FILEMODE(ftyp);
  41.    results = creat(name, mode);
  42.  
  43.    if (results != -1)
  44.       return results;
  45.  
  46.    /* see if we need to make any intermediate directories */
  47.    path = strdup(name);
  48.  
  49.    if ((last = strrchr(path, '/')) != nil(char)) {
  50.       *last = '\0';
  51.       MKDIR(path);
  52.    }
  53.    else if ((last = strrchr(path, '\\')) != nil(char)) {
  54.       *last = '\0';
  55.       MKDIR(path);
  56.    }
  57.  
  58.    free(path);
  59.  
  60.    /* now try open again */
  61.    return creat(name, mode);
  62.  
  63. } /*CREAT*/
  64.